package jangdolbaeng2.seller.dao;

import jangdolbaeng2.db.MybatisConfig;
import jangdolbaeng2.vo.Shop_blogVO;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/*
 * 작성자 : 진승민
 * 기능 : DB의 Blog Table 제어해 블로그 제작에 필요한 자료를 주고받는다.*/

public class BuilderDao {
	SqlSessionFactory factory = MybatisConfig.getSqlSessionFactory();
	
	public void imageUpload(String ImgData){		
		SqlSession ss = factory.openSession();
		//System.out.println("dao:" +ImgData);
		try{
			ss.insert("builder.imageUpload", ImgData);
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	public String imageDownload(String shopName){		
		SqlSession ss = factory.openSession();
		String ImgData = null;
		try{
			ImgData=ss.selectOne("builder.imageDownload", shopName);
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return ImgData;
	}
	
	public List<String> imageList(){		
		SqlSession ss = factory.openSession();
		List<String> ImgData = null;
		try{
			ImgData=ss.selectList("builder.imageList");
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return ImgData;
	}
	
	public int blogSetting(Shop_blogVO vo){
		//System.out.println("dao:"+vo);
		SqlSession ss = factory.openSession();
		int result=0;
		try{
			result=ss.update("builder.blogSetting", vo);
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}		
		finally {
			if (ss != null) ss.close();
		}
		return result;
	}
	
	public List<String> skinList(){
		SqlSession ss = factory.openSession();
		List<String> skins = null;
		try{
			skins=ss.selectList("builder.skinList");
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return skins;
	}
	public List<String> fontList(){
		SqlSession ss = factory.openSession();
		List<String> skins = null;
		try{
			skins=ss.selectList("builder.fontList");
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return skins;
	}
	public List<String> colorList(){
		SqlSession ss = factory.openSession();
		List<String> skins = null;
		try{
			skins=ss.selectList("builder.colorList");
			ss.commit();
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return skins;
	}
}
